﻿namespace WebPacker.Tests.Packs.Resources
{
	using System;
	using System.IO;
	using System.Text;
	using NUnit.Framework;
	using WebPacker.Packs.Resources;

	[TestFixture]
	public class RemoteResourceTest
	{
		private readonly string testFilePath = @"samples\source\swfobject_src.js";
		private readonly string testFileUrl = "https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject_src.js";
		private readonly DateTime lastModifiedTime = new DateTime(2010, 2, 10, 4, 5, 2);

		[Test]
		public void ConstructorTest()
		{
			var resource = new RemoteResource(testFileUrl);
			Assert.AreEqual(testFileUrl, resource.Name);
			Assert.AreEqual(false, resource.EnableMonitoring);
		}

		[Test]
		public void GetContentTest()
		{
			var resource = new RemoteResource(testFileUrl);
			var expected = File.ReadAllText(testFilePath, Encoding.UTF8).Replace("\r", string.Empty);
			var actual = resource.GetContent();
			Assert.AreEqual(expected, actual);
		}

		[Test]
		public void GetContentWithHttpCacheTest()
		{
			var resource = new RemoteResource(testFileUrl);
			var expected = File.ReadAllText(testFilePath, Encoding.UTF8).Replace("\r", string.Empty);
			var actual = resource.GetContent();
			Assert.AreEqual(expected, actual);
			var newContent = resource.GetContent();
			Assert.AreSame(actual, newContent);
		}

		[Test]
		public void GetLastModifiedTimeTest()
		{
			var resource = new RemoteResource(testFileUrl);
			Assert.AreEqual(lastModifiedTime, resource.GetLastModifiedTime());
		}
	}
}
